package com.fanbai.score.business.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.fanbai.score.R;
import com.fanbai.score.business.beans.StaffInfo_Bean;
import com.fanbai.score.business.http.Busin_Goods_RequestNet;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ToastUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.http.CallBack;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by acer on 2017/6/18.
 */

public class StaffList_Activity extends BaseActivity{

    @BindView(R.id.view_recyclerView)
    RecyclerView mRecyclerView;

    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_commonlist;
    }

    @Override
    public String getTitleName() {
        return "店员列表";
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        String sid = getIntent().getExtras().getString("sid");
        getshopclerkinfos(sid);

    }

    private void setData(final List<StaffInfo_Bean> beans){

        List<String> dataList = new ArrayList<>();
        dataList.add("htsec01.png");
        dataList.add("htsec01.png");
        dataList.add("htsec01.png");

        mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
        CommonAdapter adapter = new CommonAdapter<StaffInfo_Bean>(ctx, R.layout.business_item_activity_staffactivity,
                beans){
            @Override
            protected void convert(final ViewHolder holder, StaffInfo_Bean bean, int position) {
                holder.setText(R.id.businessItemActivityStaffList_name, bean.getSmpersonname()+" "+bean.getSmmobile());
                holder.setText(R.id.businessItemActivityStaffList_shopName, bean.getSinfo().getSname());
            }
        };
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("smuid", beans.get(position).getSmuid());
                jumpToActivity(OrderList_Activity.class, bundle);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    protected void initListener() {

    }

    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }

    private void getshopclerkinfos(String sid){
        showDialog();
        Busin_Goods_RequestNet.getshopclerkinfos(ctx, sid, new CallBack<List<StaffInfo_Bean>>() {
            @Override
            public void onSuccess(String code, String msg, List<StaffInfo_Bean> beans) {
                hideDialog();
                setData(beans);
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }

}
